Customize Formatting
Respecting specific coding guidelines is crucial for maintaining a consistent codebase. In case the Code Style does not fit your needs, you can customize specific formatting rules.
The settings bellow override behaviour set with the "php.format.codestyle"
style.
- Settings:
php.format.rules.*
- License: PREMIUM.
Customize Settings in VS Code Settings UI
Browse through all the custom rules in Visual Studio Code Settings UI. Open command palette (Ctrl+Shift+P
) and type Preferences: Open User Settings (UI)
. Then search for php.format
and you will see all the available settings, including examples.
Indentation
IndentBraces: Gets value indicating whether to indent braces
- setting:
php.format.rules.indentBraces
- .editorconfig directive:
php_format_indent_braces
|
|
true | false |
Spacing
Space after cast: Insert a space after a cast operator.
- setting:
php.format.rules.spaceAfterCast
- .editorconfig directive:
php_format_space_after_cast
|
|
true | false |
Space after unary not !
: Insert a space after a unary not operator.
- setting:
php.format.rules.spaceAfterUnaryNot
- .editorconfig directive:
php_format_space_after_unary_not
|
|
true | false |
Space around concatenation .
: Insert a space around concatenation operator.
- setting:
php.format.rules.spaceAroundConcatenation
- .editorconfig directive:
php_format_space_around_concatenation
|
|
true | false |
Space before colon :
in control flow statements: Insert a space before colon in control flow blocks.
- setting:
php.format.rules.spaceBeforeColonInControlStatements
- .editorconfig directive:
php_format_space_before_colon_in_control_statements
|
|
true | false |
Space before colon :
in return type: Insert a space before colon in a return type
- setting:
php.format.rules.spaceBeforeColonInReturnType
- .editorconfig directive:
php_format_space_before_colon_in_return_type
|
|
true | false |
Space before parentheses in arrow functions: Insert a space before arrow function parentheses.
- setting:
php.format.rules.spaceBeforeParenthesesInArrowFunctions
- .editorconfig directive:
php_format_space_before_parentheses_in_arrow_functions
|
|
true | false |
Space before parentheses in function calls: Insert a space before parentheses in method, function and constructor call parentheses.
- setting:
php.format.rules.spaceBeforeParenthesesInCalls
- .editorconfig directive:
php_format_space_before_parentheses_in_calls
|
|
true | false |
Space before parentheses in control statements: Insert a space before parentheses in control statements.
- setting:
php.format.rules.spaceBeforeParenthesesInControlStatements
- .editorconfig directive:
php_format_space_before_parentheses_in_control_statements
|
|
true | false |
Space before parentheses in declarations: Insert a space before parentheses in method, function and constructor declaration parentheses.
- setting:
php.format.rules.spaceBeforeParenthesesInDeclarations
- .editorconfig directive:
php_format_space_before_parentheses_in_declarations
|
|
true | false |
Space within array initializer parentheses: Insert a space within array initializer parentheses.
- setting:
php.format.rules.spaceWithinArrayInitilizersParens
- .editorconfig directive:
php_format_space_within_array_initilizers_parens
|
|
true | false |
Space within brackets []
: Insert a space within brackets.
- setting:
php.format.rules.spaceWithinBrackets
- .editorconfig directive:
php_format_space_within_brackets
|
|
true | false |
Space within brackets []
around expression: Insert a space within brackets around expression.
- setting:
php.format.rules.spaceWithinBracketsAroundExpression
- .editorconfig directive:
php_format_space_within_brackets_around_expression
|
|
true | false |
Space within call parentheses: Insert a space within method, function and constructor call parentheses.
- setting:
php.format.rules.spaceWithinCallParens
- .editorconfig directive:
php_format_space_within_call_parens
|
|
true | false |
Space within catch
parentheses: Insert a space within catch
statement header parentheses.
- setting:
php.format.rules.spaceWithinCatchParens
- .editorconfig directive:
php_format_space_within_catch_parens
|
|
true | false |
Space within declaration parentheses: Insert a space within method, function and constructor declaration parentheses.
- setting:
php.format.rules.spaceWithinDeclParens
- .editorconfig directive:
php_format_space_within_decl_parens
|
|
true | false |
Space within parentheses around expression: Insert a space within parentheses around expression.
- setting:
php.format.rules.spaceWithinExpressionParens
- .editorconfig directive:
php_format_space_within_expression_parens
|
|
true | false |
Space within for
parentheses: Insert a space within for
statement header parentheses.
- setting:
php.format.rules.spaceWithinForParens
- .editorconfig directive:
php_format_space_within_for_parens
|
|
true | false |
Space within foreach
parentheses: Insert a space within foreach
statement header parentheses.
- setting:
php.format.rules.spaceWithinForeachParens
- .editorconfig directive:
php_format_space_within_foreach_parens
|
|
true | false |
Space within if
parentheses: Insert a space within if
statement header parentheses.
- setting:
php.format.rules.spaceWithinIfParens
- .editorconfig directive:
php_format_space_within_if_parens
|
|
true | false |
Space within switch
parentheses: Insert a space within switch
statement header parentheses.
- setting:
php.format.rules.spaceWithinSwitchParens
- .editorconfig directive:
php_format_space_within_switch_parens
|
|
true | false |
Space within while
parentheses: Insert a space within while
statement header parentheses.
- setting:
php.format.rules.spaceWithinWhileParens
- .editorconfig directive:
php_format_space_within_while_parens
|
|
true | false |
NewLines
catch
on a new line: Place catch
on a new line.
- setting:
php.format.rules.catchOnNewLine
- .editorconfig directive:
php_format_catch_on_new_line
|
|
true | false |
else
on a new line: Place else
on a new line.
- setting:
php.format.rules.elseOnNewLine
- .editorconfig directive:
php_format_else_on_new_line
|
|
true | false |
Insert final newline: Inserts final newline at the end of a file.
- setting:
php.format.rules.endWithNewLine
- .editorconfig directive:
php_format_end_with_new_line
finally
on a new line: Place finally
on a new line.
- setting:
php.format.rules.finallyOnNewLine
- .editorconfig directive:
php_format_finally_on_new_line
|
|
true | false |
Open brace on a new line for anonymous classes: Place open brace {
on a new line for anonymous classes.
- setting:
php.format.rules.openBraceOnNewLineForAnonymousClasses
- .editorconfig directive:
php_format_open_brace_on_new_line_for_anonymous_classes
|
|
true | false |
Open brace on a new line for blocks: Place open brace {
on a new line for all types of code blocks, except for those controlled by other formatting rules.
- setting:
php.format.rules.openBraceOnNewLineForBlocks
- .editorconfig directive:
php_format_open_brace_on_new_line_for_blocks
|
|
true | false |
Open brace on a new line for functions: Place open brace {
on a new line for methods, functions and constructors.
- setting:
php.format.rules.openBraceOnNewLineForFunctions
- .editorconfig directive:
php_format_open_brace_on_new_line_for_functions
|
|
true | false |
Open brace on a new line for lambda functions: Place open brace {
on a new line for lambda functions.
- setting:
php.format.rules.openBraceOnNewLineForLambdas
- .editorconfig directive:
php_format_open_brace_on_new_line_for_lambdas
|
|
true | false |
Open brace on a new line for namespaces: Place open brace {
on a new line for namespace declarations.
- setting:
php.format.rules.openBraceOnNewLineForNamespaces
- .editorconfig directive:
php_format_open_brace_on_new_line_for_namespaces
|
|
true | false |
Open brace on a new line for types: Place open brace {
on a new line for types.
- setting:
php.format.rules.openBraceOnNewLineForTypes
- .editorconfig directive:
php_format_open_brace_on_new_line_for_types
|
|
true | false |
Wrapping
Align consecutive = assignments.: Automatically align consecutive =
assignments.
- setting:
php.format.rules.alignConsecutiveAssignments
- .editorconfig directive:
php_format_align_consecutive_assignments
|
|
true | false |
Align constants: Automatically align constant declarations
- setting:
php.format.rules.alignConstants
- .editorconfig directive:
php_format_align_constants
|
|
true | false |
Align enum cases: Automatically align assigned values in backed enumerations
- setting:
php.format.rules.alignEnumCases
- .editorconfig directive:
php_format_align_enum_cases
|
|
true | false |
Align match
arm bodies: Automatically align the bodies (results) within match
expression arms
- setting:
php.format.rules.alignMatchArmBodies
- .editorconfig directive:
php_format_align_match_arm_bodies
|
|
true | false |
Align properties: Automatically align properties declarations
- setting:
php.format.rules.alignProperties
- .editorconfig directive:
php_format_align_properties
|
|
true | false |
Align key-value pairs: Automatically align =>
operators.
- setting:
php.format.rules.arrayInitializersAlignKeyValuePairs
- .editorconfig directive:
php_format_array_initializers_align_key_value_pairs
|
|
true | false |
New line after last element: Place a new line after the last element when wrapping.
- setting:
php.format.rules.arrayInitializersNewLineAfterLastElement
- .editorconfig directive:
php_format_array_initializers_new_line_after_last_element
|
|
true | false |
New line before first element: Place a new line before the first array element when wrapping.
- setting:
php.format.rules.arrayInitializersNewLineBeforeFirstElement
- .editorconfig directive:
php_format_array_initializers_new_line_before_first_element
|
|
true | false |
Wrap: _Defines wrapping behavior for array initializers.
-
Off
- No wrapping is applied -
On every item
- When this option is selected each item is placed on a new line and properly indented if the array initializer is split across multiple lines. _ -
setting:
php.format.rules.arrayInitializersWrap
-
.editorconfig directive:
php_format_array_initializers_wrap
New line after (
: Place a new line after the left opening parenthesis (
when wrapping.
- setting:
php.format.rules.callParametersNewLineAfterLeftParen
- .editorconfig directive:
php_format_call_parameters_new_line_after_left_paren
|
|
true | false |
New line before )
: Place a new line before the right closing parenthesis )
when wrapping.
- setting:
php.format.rules.callParametersNewLineBeforeRightParen
- .editorconfig directive:
php_format_call_parameters_new_line_before_right_paren
|
|
true | false |
Wrap: _Defines wrapping behavior for method, function and constructor call parameters.
-
Off
- No wrapping is applied -
On every item
- When this option is selected each item is placed on a new line and properly indented if the call arguments are split across multiple lines. _ -
setting:
php.format.rules.callParametersWrap
-
.editorconfig directive:
php_format_call_parameters_wrap
;
on a new line: Place ;
on a new line after the last element in the chained method call when wrapping.
- setting:
php.format.rules.chainedMethodCallsSemicolonOnNewLine
- .editorconfig directive:
php_format_chained_method_calls_semicolon_on_new_line
|
|
true | false |
Wrap: _Defines wrapping behavior for chained method calls.
-
Off
- No wrapping is applied -
Always
- When this option is selected each method call is placed on a new line and properly indented. _ -
setting:
php.format.rules.chainedMethodCallsWrap
-
.editorconfig directive:
php_format_chained_method_calls_wrap
Compact empty body into {}
: Transform empty body into {}
and keep it at the same line as a previous symbol, separated by single space.
- setting:
php.format.rules.declCompactEmptyBody
- .editorconfig directive:
php_format_decl_compact_empty_body
|
|
true | false |
Keep )
and {
on one line: Keep the right closing parenthesis )
of a function or method declaration header on the one line as opening brace of the body {
.
- setting:
php.format.rules.declKeepRightParenAndOpenBraceOnOneLine
- .editorconfig directive:
php_format_decl_keep_right_paren_and_open_brace_on_one_line
|
|
true | false |
New line after (
: Place a new line after the left opening parenthesis (
of function or method declaration header when wrapping.
- setting:
php.format.rules.declParametersNewLineAfterLeftParen
- .editorconfig directive:
php_format_decl_parameters_new_line_after_left_paren
|
|
true | false |
New line before )
: Place a new line before the right closing parenthesis )
of a function or method declaration header when wrapping.
- setting:
php.format.rules.declParametersNewLineBeforeRightParen
- .editorconfig directive:
php_format_decl_parameters_new_line_before_right_paren
|
|
true | false |
Wrap: _Defines wrapping behavior for method or function declaration parameters.
-
Off
- No wrapping is applied -
On every item
- When this option is selected each declaration parameter is placed on a new line and properly indented if the arguments are split across multiple lines. _ -
setting:
php.format.rules.declParametersWrap
-
.editorconfig directive:
php_format_decl_parameters_wrap
New line after (
: Place a new line after the left opening parenthesis (
in a for
statement header if it's split across multiple lines.
- setting:
php.format.rules.forStatementNewLineAfterLeftParen
- .editorconfig directive:
php_format_for_statement_new_line_after_left_paren
|
|
true | false |
New line before )
: Place a new line after the right closing parenthesis )
in a for
statement header if it's split across multiple lines.
- setting:
php.format.rules.forStatementNewLineBeforeRightParen
- .editorconfig directive:
php_format_for_statement_new_line_before_right_paren
|
|
true | false |
Wrap: _Defines wrapping behavior for for
statement.
-
Off
- No wrapping is applied -
On every item
- When this option is selected each item infor
statement is placed on a new line and properly indented if they are split across multiple lines. _ -
setting:
php.format.rules.forStatementWrap
-
.editorconfig directive:
php_format_for_statement_wrap
New line before first group use
declaration: Place a new line before first group use
declaration if the list of declarations is split across multiple lines.
- setting:
php.format.rules.groupUseNewLineBeforeFirstDeclaration
- .editorconfig directive:
php_format_group_use_new_line_before_first_declaration
|
|
true | false |
Wrap: _Defines wrapping behavior for group use
list in type declarations.
-
Off
- No wrapping is applied -
On every item
- When this option is selected each declaration in groupuse
list is placed on a new line and properly indented if they are split across multiple lines. _ -
setting:
php.format.rules.groupUseWrap
-
.editorconfig directive:
php_format_group_use_wrap
New line after (
: Place a new line after the left opening parenthesis (
in a if
or elseif
statement header if it's split across multiple lines.
- setting:
php.format.rules.ifStatementNewLineAfterLeftParen
- .editorconfig directive:
php_format_if_statement_new_line_after_left_paren
|
|
true | false |
New line before )
: Place a new line after the right closing parenthesis )
in a if
or elseif
statement header if it's split across multiple lines.
- setting:
php.format.rules.ifStatementNewLineBeforeRightParen
- .editorconfig directive:
php_format_if_statement_new_line_before_right_paren
|
|
true | false |
Wrap: _Defines wrapping behavior for implements
list in type declarations.
-
Off
- No wrapping is applied -
On every item
- When this option is selected each interface inimplements
list is placed on a new line and properly indented if they are split across multiple lines. _ -
setting:
php.format.rules.implementsListWrap
-
.editorconfig directive:
php_format_implements_list_wrap
Heredoc/Nowdoc Content Indentation: Ensures heredoc and nowdoc content lines are indented one level past the declaration's scope.
- setting:
php.format.rules.indentHeredoc
- .editorconfig directive:
php_format_indent_heredoc
|
|
true | false |
Inline Heredoc/Nowdoc Declaration: Place heredoc and nowdoc on the same line as declaring variable
- setting:
php.format.rules.inlineHeredoc
- .editorconfig directive:
php_format_inline_heredoc
|
|
true | false |
Keep classes on one line: Clasess are kept on one line.
- setting:
php.format.rules.keepClassesOnOneLine
- .editorconfig directive:
php_format_keep_classes_on_one_line
|
|
true | false |
Keep control statements on one line: Control statements are kept on one line.
- setting:
php.format.rules.keepControlStatementsOnOneLine
- .editorconfig directive:
php_format_keep_control_statements_on_one_line
|
|
true | false |
Keep functions on one line: Functions and methods are kept on one line.
- setting:
php.format.rules.keepFunctionsOnOneLine
- .editorconfig directive:
php_format_keep_functions_on_one_line
|
|
true | false |
New line after implements
: Place a new line after implements
in type declaration if the list of interfaces is split across multiple lines.
- setting:
php.format.rules.newLineAfterImplements
- .editorconfig directive:
php_format_new_line_after_implements
|
|
true | false |
New line after (
: Place a new line after the left opening parenthesis (
in a switch
statement header if it's split across multiple lines.
- setting:
php.format.rules.switchStatementNewLineAfterLeftParen
- .editorconfig directive:
php_format_switch_statement_new_line_after_left_paren
|
|
true | false |
New line before )
: Place a new line after the right closing parenthesis )
in a switch
statement header if it's split across multiple lines.
- setting:
php.format.rules.switchStatementNewLineBeforeRightParen
- .editorconfig directive:
php_format_switch_statement_new_line_before_right_paren
|
|
true | false |
New line after (
: Place a new line after the left opening parenthesis (
in a while
statement header if it's split across multiple lines.
- setting:
php.format.rules.whileStatementNewLineAfterLeftParen
- .editorconfig directive:
php_format_while_statement_new_line_after_left_paren
|
|
true | false |
New line before )
: Place a new line after the right closing parenthesis )
in a while
statement header if it's split across multiple lines.
- setting:
php.format.rules.whileStatementNewLineBeforeRightParen
- .editorconfig directive:
php_format_while_statement_new_line_before_right_paren
|
|
true | false |
Conversions
Add a comma after the last array element: Automatically adds a comma after the last array element if it's not on a single line.
- setting:
php.format.rules.addCommaAfterLastArrayElement
- .editorconfig directive:
php_format_add_comma_after_last_array_element
Add a comma after the last function call parameters: Automatically adds a comma after the last function call parameter if it's not on a single line.
- setting:
php.format.rules.addCommaAfterLastCallParameter
- .editorconfig directive:
php_format_add_comma_after_last_call_parameter
Add a comma after the last function declaration parameters: Automatically adds a comma after the last function or method declaration parameter if it's not on a single line.
- setting:
php.format.rules.addCommaAfterLastDeclParameter
- .editorconfig directive:
php_format_add_comma_after_last_decl_parameter
Boolean constant casing: _Defines casing for true
and false
constants.
-
uppercase
- Changes the casing to upper case -
lowercase
- Changes the casing to lower case -
keep
- Keeps the original casing _ -
setting:
php.format.rules.booleanConstantCasing
-
.editorconfig directive:
php_format_boolean_constant_casing
|
|
lowercase | uppercase |
Null constant casing: _Defines casing for null
constant.
-
uppercase
- Changes the casing to upper case -
lowercase
- Changes the casing to lower case -
keep
- Keeps the original casing _ -
setting:
php.format.rules.nullConstantCasing
-
.editorconfig directive:
php_format_null_constant_casing
|
|
lowercase | uppercase |
BlankLines
Blank lines after class: Defines the number of blank lines after a class declaration.
- setting:
php.format.rules.blankLinesAfterClass
- .editorconfig directive:
php_format_blank_lines_after_class
Blank lines after class body: Defines the number of blank lines after a class body.
- setting:
php.format.rules.blankLinesAfterClassBody
- .editorconfig directive:
php_format_blank_lines_after_class_body
Blank lines after function: Defines the number of blank lines after a function declaration.
- setting:
php.format.rules.blankLinesAfterFunction
- .editorconfig directive:
php_format_blank_lines_after_function
Blank lines after method: Defines the number of blank lines after a method declaration.
- setting:
php.format.rules.blankLinesAfterMethod
- .editorconfig directive:
php_format_blank_lines_after_method
Blank lines after namespace: Defines the number of blank lines after a namespace declaration.
- setting:
php.format.rules.blankLinesAfterNamespace
- .editorconfig directive:
php_format_blank_lines_after_namespace
Blank lines after use statements: Defines the number of blank lines after 'use' statements.
- setting:
php.format.rules.blankLinesAfterUseStatements
- .editorconfig directive:
php_format_blank_lines_after_use_statements
Blank lines before class: Defines the number of blank lines before a class declaration.
- setting:
php.format.rules.blankLinesBeforeClass
- .editorconfig directive:
php_format_blank_lines_before_class
Blank lines before class body: Defines the number of blank lines before a class body.
- setting:
php.format.rules.blankLinesBeforeClassBody
- .editorconfig directive:
php_format_blank_lines_before_class_body
Blank lines before function: Defines the number of blank lines before a function declaration.
- setting:
php.format.rules.blankLinesBeforeFunction
- .editorconfig directive:
php_format_blank_lines_before_function
Blank lines before function body: Defines the number of blank lines before a function body.
- setting:
php.format.rules.blankLinesBeforeFunctionBody
- .editorconfig directive:
php_format_blank_lines_before_function_body
Blank lines before method: Defines the number of blank lines before a method declaration.
- setting:
php.format.rules.blankLinesBeforeMethod
- .editorconfig directive:
php_format_blank_lines_before_method
Blank lines before method body: Defines the number of blank lines before a method body.
- setting:
php.format.rules.blankLinesBeforeMethodBody
- .editorconfig directive:
php_format_blank_lines_before_method_body
Blank lines before namespace: Defines the number of blank lines before a namespace declaration.
- setting:
php.format.rules.blankLinesBeforeNamespace
- .editorconfig directive:
php_format_blank_lines_before_namespace
Blank lines before use statements: Defines the number of blank lines before 'use' statements.
- setting:
php.format.rules.blankLinesBeforeUseStatements
- .editorconfig directive:
php_format_blank_lines_before_use_statements
Maximum blank lines in code: Defines the maximum number of consecutive blank lines allowed in the code.
- setting:
php.format.rules.maxBlankLines
- .editorconfig directive:
php_format_max_blank_lines